<?php
 class PersonAction extends LockAction{
 	public function index(){
 		$this->display();
 	}
 	// 查看联系方式
 	public function touch(){
 		$touch=M('Touch');
 		$user_id=$_SESSION['home_user_id'];
 		// $sql1="select count(*) tot from touch";
 		$count=$touch->where('user_id='.$user_id)->count();
 		import('ORG.Util.Page');
 		$page=New page($count,10);
 		$show=$page->show();
 		$touchrows=$touch->where('user_id='.$user_id)->limit($page->firstRow.','.$page->listRows)->select();
 		$this->assign('touchrows',$touchrows);
 		$this->assign('show',$show);
 		$this->display();
 	}
 	// 添加联系方式
 	public function addTouch(){
 		$this->display();
 	}
 	// 添加联系方式操作
 	public function addTouchhandle(){
 		$touch=M('Touch');
 		$_POST['user_id']=$_SESSION['home_user_id'];
 		if($touch->add($_POST)){
 			$this->redirect('Person/touch');
 		}
 		
 	}
 	// 修改联系方式
 	public function touchEdit(){
 		$touch=M('Touch');
 		$id=$_GET['id'];
 		$touchrow=$touch->find($id);
 		$this->assign('touchrow',$touchrow);
 		$this->display();

 	}

 	// 修改联系方式操作
 	public function touchEdithandle(){
 		$touch=M('Touch');
 		$re=$touch->save($_POST);
 		if($re){

 			$this->redirect('Person/touch');
 		}
 	}

 	// 删除联系方式
 	public function touchDel(){
 		$touch=M('Touch');
 		$id=$_GET['id'];
 		if($touch->delete($id)){
 			$this->redirect('Person/touch');
 		}
 	}
 	// 查看订单
 	public function orderList(){
 		$db=M();
 		$user_id=$_SESSION['home_user_id'];
 		$sql="select count(*) tot from indent  where user_id={$user_id}";
 		$count=$db->query($sql);
 		$tot=$count[0]['tot'];
 		import('ORG.Util.Page');
 		$page=New page($tot,10);
 		$show=$page->show();
 		$sql2="select i.*,s.name from indent i,status s 
 				where i.user_id={$user_id} and i.status_id=s.id
 				group by i.code
 				limit {$page->firstRow},{$page->listRows}
 				";
 		$indentrows=$db->query($sql2);
 		$this->assign('indentrows',$indentrows);
 		$this->assign('show',$show);
 		$this->display();
 	}
 	// 订单详情
 	public function orderDetail(){
 		$db=M();
 		$code=$_GET['code'];
 		$sql="select i.*,s.name,s.img,s.price from indent i,shop s 
 				where i.shop_id=s.id and i.code={$code}";
 		$rows=$db->query($sql);
 		$this->assign('rows',$rows);
 		$this->display();
 	}
 	// 是否确认收货
 	public function confirm(){
 		$code=$_GET['code'];
 		$data['is_comment']=1;
 		$indent=M('Indent');
 		$indent->where('code='.$code)->save($data);
 		$this->redirect('Person/orderList');
 	}
 	// 评论页面
 	public function comment(){
 		$db=M();
 		$code=$_GET['code'];
 		$sql="select i.*,s.name,s.id sid,s.img,s.price from indent i,shop s 
 				where i.shop_id=s.id and i.code={$code}";
 		$rows=$db->query($sql);
 		$this->assign('rows',$rows);
 		$this->display();
 	}

 	// 提交评论
 	public function submit_comment(){
 		$_POST['user_id']=$_SESSION['home_user_id'];
 		$_POST['shop_id']=$_POST['sid'];
 		$_POST['time']=time();
 		if(M('Comment')->add($_POST)){
 			$this->redirect('Person/orderlist');
 		}
 		
 	}
 }
?>